package com.efast.cafe.portal.controller.common;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.cafe.framework.controller.AbstractController;
import com.efast.cafe.portal.bean.common.LeaveMessageBean;
import com.efast.cafe.portal.entity.common.PortalCommonLeavemsg;
import com.efast.cafe.portal.service.common.IPortalCommonLeavemsgService;

@Controller
public class CommonLeavemsgController extends AbstractController{

	@Autowired
	private IPortalCommonLeavemsgService portalCommonLeavemsgService;

	
	
	/**
	 * 留言列表
	 * @param objectType
	 * @param objectId
	 * @return
	 */
	@RequestMapping(value = "/frame_center/common/queryLeavemsg")
	public @ResponseBody ResultBean queryLeavemsg(
			@RequestParam String objectType,@RequestParam Integer objectId){
		ResultBean res = new ResultBean(true, "");
		List<LeaveMessageBean> obj = portalCommonLeavemsgService.queryLeavemsg(objectId, objectType);
		res.setObject(obj);
		return res;
	}
	/**
	 * 添加留言
	 * @param msg
	 * @return
	 */
	@RequestMapping(value = "/frame_center/common/addLeavemsg")
	public @ResponseBody ResultBean addLeavemsg(@ModelAttribute("msg") PortalCommonLeavemsg msg){
		try{
			//接受返回的id
			int id=portalCommonLeavemsgService.addLeavemsg(msg);
			LeaveMessageBean mcl=portalCommonLeavemsgService.queryLeavemsgById(id, msg.getObjectId(), msg.getObjectType());
			 ResultBean res = new ResultBean(true,ADD_SUCCESS_TIP);
			 res.setObject(mcl);
			 return res;
		}catch(Exception e){
			return new ResultBean(false, ADD_FAILURE_TIP,msg.getMsg());
		}
		
	}
	
	/**
	 * 刪除留言
	 * @param msg
	 * @return
	 */
	@RequestMapping(value = "/frame_center/common/delLeavemsg")
	public @ResponseBody ResultBean delLeavemsg(@RequestParam String objectType,@RequestParam Integer objectId,@RequestParam Integer id){
		try{
			portalCommonLeavemsgService.delLeavemsg(id, objectId, objectType);
			return new ResultBean(true,DEL_SUCCESS_TIP);
		}catch(Exception e){
			return new ResultBean(false, DEL_FAILURE_TIP);
		}
		
	}
}
